//package com.studerb.tasks.newsGroups;
//
//import java.io.BufferedReader;
//import java.util.concurrent.BlockingQueue;
//import java.util.concurrent.Callable;
//
//import org.apache.commons.net.io.DotTerminatedMessageReader;
//import org.apache.commons.net.nntp.NNTPCommand;
//import org.apache.commons.net.nntp.NNTPReply;
//import org.apache.log4j.Logger;
//import org.springframework.beans.BeansException;
//import org.springframework.beans.factory.annotation.Autowired;
//import org.springframework.context.ApplicationContext;
//import org.springframework.context.ApplicationContextAware;
//import org.springframework.context.support.GenericApplicationContext;
//
//import com.studerb.exceptions.ServiceException;
//import com.studerb.model.Server;
//import com.studerb.nntp.NntpConnection;
//import com.studerb.service.ServerService;
//import com.studerb.util.Constants;
//
//public class ListCommandProducerTask implements Runnable {
//
//	private final static Logger log = Logger.getLogger(ListCommandProducerTask.class);
//	private final static int LOG_COUNT = 10000;
//	private GenericApplicationContext appContext;
//	private NntpConnection conn;
//	private BlockingQueue<String> queue;
//	private Server master;
//	private BufferedReader reader;
//	@Autowired private ServerService serverService;
//
//	public ListCommandProducerTask(BlockingQueue<String> queue, NntpConnection conn){
//		this.queue = queue;
//		this.conn = conn;
//	}
//
//	public void run() {
//		log.debug("group producer starting");
//		try {
//			log.info("updating all groups from server: " + master.toString());
//			int reply = this.conn.sendCommand(NNTPCommand.LIST);
//			if ((!NNTPReply.isPositiveCompletion(reply)) || (reply != NNTPReply.LIST_OF_NEWSGROUP_FOLLOWS))
//				throw new ServiceException("Error listing groups: reply: " + conn.getReply());
//			reader = new BufferedReader(new DotTerminatedMessageReader(conn.getReader()));
//			String temp;
//			int count = 0;
//			while ((temp = reader.readLine()) != null) {
//				queue.put(temp);
//				++count;
//				if (count % LOG_COUNT == 0)
//					log.debug(count + ": " + temp);
//			}
////			log.debug("Finished downloading " + count + " groups");
//		} finally {
//			queue.put(Constants.END_OF_QUEUE);
//		}
//	}
//
//	public void setQueue(BlockingQueue<String> queue) {
//		this.queue = queue;
//	}
//}
